<?php

class Upload extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
	}

	function index()
	{
		$this->load->view('upload/upload_form', array('error' => ' ' ));
	}

	function do_upload()
	{
		// 上传文件配置
		// $this->upload->file_name = iconv("UTF-8","GB2312//IGNORE",$_FILES['files']['name'])
		// 系统不同可能有问题，尽量不用这种方式
		$up_config['upload_path'] = './uploads/';
		$up_config['allowed_types'] = 'gif|jpg|png|txt';
		$up_config['max_size'] = '100';
		$up_config['max_width']  = '1024';
		$up_config['max_height']  = '768';
		$this->load->library('upload', $up_config); // 启用上传类

		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());
			$this->load->view('upload/upload_form', $error);
		}
		else
		{
			$data = array('upload_data' => $this->upload->data());

			// 图像处理配置
			$img_config['image_library'] = 'gd2';
			$img_config['source_image'] = base_url().'uploads/'.$data['upload_data']['orig_name'];
			$img_config['create_thumb'] = true;
			$img_config['maintain_ratio'] = true;
			$img_config['width'] = 50;
			$img_config['height'] = 50;
			$this->load->library('image_lib'); // 启用图像处理类
			$this->image_lib->resize(); // 进行处理

			var_dump($img_config);

			$this->load->view('upload/upload_success', $data);
		}
	}
}
?>